//
//  LawLibraryViewController.m
//  HONGQIYUN
//
//  Created by 余海华 on 2016/12/19.
//  Copyright © 2016年 Haidi. All rights reserved.
//

#import "LawLibraryViewController.h"

/// controller

/// view
#import "HQYSearchControlView.h"
#import "HQYLawLibraryTypeView.h"

/// model
#import "IHomeClient.h"

const static CGFloat kSearControlViewHeight = 40.f;

@interface LawLibraryViewController ()

@property (nonatomic, strong )HQYSearchControlView *searchControlView;

@property (nonatomic, strong) HQYLawLibraryTypeView *lawLibraryTypeView;

@property (nonatomic, strong) LawLibrary *lawLibray;

@end

@implementation LawLibraryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self loadData];
}

- (void)loadView {
    [super loadView];
    
    [self.searchControlView setFrame:CGRectMake(10, 10, ScreenWidth - 20, kSearControlViewHeight)];
    [self.view addSubview:self.searchControlView];

}

- (void)loadData {
    [self showHudInView:self.view hint:kLoadingText];
    
    [GetCoreI(IHomeClient) requestLawLibCategoryListWithCname:@"flwk" andCid:@"0" SuccBlock:^(LawLibrary *lawLibrayObject) {
        self.lawLibray = lawLibrayObject;
        [self reloadContentView];
        [self hideHud];
    } failBlock:^(NSString *msg) {
        [self hideHud];
    }];
}

- (void)reloadContentView {
    if(![self.lawLibraryTypeView superview]) {
        [self.view addSubview:self.lawLibraryTypeView];
    }
    [self.lawLibraryTypeView reloadViewWithModel:self.lawLibray];
}

#pragma mark -lazy load
- (HQYSearchControlView *)searchControlView {
    if(!_searchControlView) {
        _searchControlView = [[HQYSearchControlView alloc]initWithFrame:CGRectZero andPlaceholderText:@"请输入法律类型,如:交通事故"];
    }
    return _searchControlView;
}

- (HQYLawLibraryTypeView *)lawLibraryTypeView {
    if(!_lawLibraryTypeView) {
        _lawLibraryTypeView = [[ HQYLawLibraryTypeView alloc]initWithFrame:CGRectMake(0, 60, ScreenWidth, kScreenHeight - 64 - 60 - 49.f)];
    }
    return _lawLibraryTypeView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
